/* ----------------------------------------------------------------------
*
* Copyright (C) 2024 XiaoFei. All rights reserved.
*
* $file:        KangWei_AD9834.h
* $Date:        01-December-2024
* $Revision:    V1.2
* $Project:     XiaoFei BSP Library
* $Taobao:      https://item.taobao.com/item.htm?abbucket=17&id=42145466614
*
* -------------------------------------------------------------------- */

#ifndef __KangWei_AD9834_H
#define __KangWei_AD9834_H

#define AD9834_SYSTEM_COLCK             75000000UL
#define AD9834_Rcc_FSY                  RCC_APB2Periph_GPIOB
#define AD9834_Port_FSY                 GPIOB
#define AD9834_Pin_FSY                  GPIO_Pin_9
#define AD9834_Rcc_SCK                  RCC_APB2Periph_GPIOB
#define AD9834_Port_SCK                 GPIOB
#define AD9834_Pin_SCK                  GPIO_Pin_8
#define AD9834_Rcc_SDA                  RCC_APB2Periph_GPIOB
#define AD9834_Port_SDA                 GPIOB
#define AD9834_Pin_SDA                  GPIO_Pin_7
#define AD9834_Rcc_RST                  RCC_APB2Periph_GPIOB
#define AD9834_Port_RST                 GPIOB
#define AD9834_Pin_RST                  GPIO_Pin_6
#define AD9834_Rcc_FS                   RCC_APB2Periph_GPIOC
#define AD9834_Port_FS                  GPIOC
#define AD9834_Pin_FS                   GPIO_Pin_13
#define AD9834_Rcc_PS                   RCC_APB2Periph_GPIOC
#define AD9834_Port_PS                  GPIOC
#define AD9834_Pin_PS                   GPIO_Pin_14

#define AD9834_FSY(x)                   GPIO_WriteBit(AD9834_Port_FSY,AD9834_Pin_FSY,(BitAction)(x))
#define AD9834_SCK(x)                   GPIO_WriteBit(AD9834_Port_SCK,AD9834_Pin_SCK,(BitAction)(x))
#define AD9834_SDA(x)                   GPIO_WriteBit(AD9834_Port_SDA,AD9834_Pin_SDA,(BitAction)(x))
#define AD9834_RST(x)                   GPIO_WriteBit(AD9834_Port_RST,AD9834_Pin_RST,(BitAction)(x))
#define AD9834_FS(x)                    GPIO_WriteBit(AD9834_Port_FS,AD9834_Pin_FS,(BitAction)(x))
#define AD9834_PS(x)                    GPIO_WriteBit(AD9834_Port_PS,AD9834_Pin_PS,(BitAction)(x))

#ifndef AD9834_FreqRegDef_def
#define AD9834_FreqRegDef_def
typedef enum
{
    AD9834_Freq0=0x4000,        /*!< The AD9834 freq reg 0 */
    AD9834_Freq1=0x8000         /*!< The AD9834 freq reg 1 */
}AD9834_FreqRegDef;
#endif

#ifndef AD9834_PhaseRegDef_def
#define AD9834_PhaseRegDef_def
typedef enum
{
    AD9834_Phase0=0xC000,       /*!< The AD9834 phase reg 0 */
    AD9834_Phase1=0xE000        /*!< The AD9834 phase reg 1 */
}AD9834_PhaseRegDef;
#endif

#ifndef AD9834_TypeDef_def
#define AD9834_TypeDef_def
typedef enum
{
    AD9834_Tri=0x2002,          /*!< The AD9834 output triangle wave */
    AD9834_Sin=0x2008,          /*!< The AD9834 output sine wave */
    AD9834_Squ=0x2028           /*!< The AD9834 output square wave */
}AD9834_TypeDef;
#endif

/* 
* @function:    KangWei_AD9834_Init
* @return:      None.
*/
void KangWei_AD9834_Init(void);

/* 
* @function:    KangWei_AD9834_SetFrequency
* @parameter:   [in]    reg             A register used to write frequency words.
* @parameter:   [in]    fre             The frequency you want to write.
* @parameter:   [in]    type            The type of waveform you want to generate.
* @return:      None.
*/
void KangWei_AD9834_SetFrequency(AD9834_FreqRegDef reg, float fre, AD9834_TypeDef type);

/* 
* @function:    KangWei_AD9834_SetPhase
* @parameter:   [in]    reg             A register used to write phase words.
* @parameter:   [in]    val             The phase you want to write.
* @return:      None.
*/
void KangWei_AD9834_SetPhase(AD9834_PhaseRegDef reg, unsigned short int val);

#endif

